package com.lizba.redis.tx;

import redis.clients.jedis.Jedis;

import java.math.BigDecimal;
import java.util.concurrent.CountDownLatch;

/**
 * <p>
 *      测试Redis事务
 * </p>
 *
 * @Author: Liziba
 * @Date: 2021/9/10 0:03
 */
public class TestTransactionDemo {

    private static CountDownLatch count = new CountDownLatch(100);

    public static void main(String[] args) throws InterruptedException {

        for (int i = 0; i < 100; i++) {
            new Thread(() -> {
                Jedis client = new Jedis("192.168.211.109", 6379);
                TransactionDemo demo = new TransactionDemo(client);
                demo.addBalance("liziba", BigDecimal.TEN);
                client.close();
                count.countDown();
            }).start();
        }

        count.await();

        Jedis client = new Jedis("192.168.211.109", 6379);
        BigDecimal amt = new TransactionDemo(client).getAmount("liziba");
        System.out.println(amt.toPlainString());
    }

}
